@echo off
echo ------------------------------------
echo Note: This will DELETE all data from 
echo previous EduShare installation
echo ------------------------------------
echo .
echo Do you wish to continue? 
echo 1. YES
echo 2. NO
set /p choice1=Enter your choice 1,2:  
if %choice1%==1 goto continue1
if %choice1%==2 exit
:continue1
echo ------------------------------------
echo .
echo Starting MySQL configuration...
set /p sname=MySQL host Name: 
set /p pname=MySQL server Port:
set /p uname=Enter MySQL admin user name:
set /p pword=Enter admin password:
echo About to rebuild database...
echo 1. CONTINUE
echo 2. SKIP
set /p choice2=Enter your choice 1,2:  
if %choice2%==1 goto continue2
if %choice2%==2 goto continue3
:continue2
mysql --user=%uname% --password=%pword% --host=%sname% --port=%pname% < sql_scripts\reload.sql
:continue3
echo Database setup completed.
echo ------------------------------------
echo .
echo Creating JDBC connection pool in Glassfish
set /p hname=Glassfish host name: 
set /p hport=Glassfish admin port: 

call asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --echo=true --interactive=true --host=%hname% --port=%hport% --restype=javax.sql.ConnectionPoolDataSource --property user=%uname%:password=%pword%:serverName=%sname%:networkProtocol=jdbc\:mysql:portNumber=%pname%:databaseName=edushare edusharePool
echo Connection pool creation finished
echo ------------------------------------
echo .
echo Creating JDBC resource
call asadmin create-jdbc-resource --host=%hname% --port=%hport% --connectionpoolid=edusharePool jdbc.eushare.datasource        
echo JDBC resource creation finished
echo ------------------------------------
echo .
set /p ctx=Context root for Edushare: 
set /p warpath=EduShare war file path: 
call asadmin deploy --host=%hname% --port=%hport% --upload=true --contextroot=%ctx% --force=true %warpath%
echo EduShare deployment finished
echo ------------------------------------
echo .
echo setup completed.
pause